package com.societyGames.codeAlong.state.codeExercise.view
{
import com.societyGames.flashForms.DockContainer;
import com.societyGames.flashForms.DockType;
import com.societyGames.flashForms.DockUnitType;
import com.societyGames.flashForms.IDialog;
import com.societyGames.flashForms.TextButton;
import com.societyGames.flashForms.Window;
import com.societyGames.flashForms.basicSkin.BasicControls;
import com.societyGames.flashForms.basicSkin.SharedTextFields;
import com.societyGames.system.EventObject;

import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

public class TextDialog extends EventDispatcher implements IDialog
{
  private var _completeEventObject:EventObject;

  public function TextDialog(windowName:String, hyperText:String)
  {
    this._completeEventObject = new EventObject(this, "COMPLETE");
    initializeGraphics(windowName, hyperText);
  }

  private function okClickCallback(event:Event):void
  {
    this._completeEventObject.dispatchEvent();
  }

  //IDialog-->
  public function get completeEventObject():EventObject
  {
    return this._completeEventObject;
  }

  public function get displayObject():DisplayObject
  {
    return this._window;
  }

  //<--IDialog

  private var _window:Window;
  private var _okButton:TextButton;

  private function initializeGraphics(windowName:String, hyperText:String):void
  {
    var textField:TextField = SharedTextFields.createHtmlTextField();
    textField.width = 200;
    textField.multiline = true;
    textField.wordWrap = true;
    textField.autoSize = TextFieldAutoSize.CENTER;
    textField.htmlText = hyperText;

    this._okButton = BasicControls.createTextButton(okClickCallback);
    this._okButton.height = BasicControls.TEXT_BUTTON_HEIGHT;
    this._okButton.text = "OK";

    var dockContainer:DockContainer = new DockContainer();
    dockContainer.addItem(this._okButton, DockType.bottom, DockUnitType.pixel, this._okButton.height);
    dockContainer.addItem(textField, DockType.fill, DockUnitType.percent, 1);
    dockContainer.width = textField.width;
    dockContainer.height = textField.height + this._okButton.height;

    this._window = BasicControls.createWindow(windowName);
    this._window.allowResize = false;
    this._window.innerWidth = dockContainer.width;
    this._window.innerHeight = dockContainer.height;
    this._window.item = dockContainer;
  }
}
}